/*
 * Copyright (c) 2011 Team A CS2340. All rights reserved.
 */

package edu.gatech.teama.doctorsoffice.model;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * PatientInstructions.java: medical information generated during an appointment 
 * for the patient
 * @author Team A
 * @version 1.0
 *
 */
public class PatientInstructions extends AbstractModelObject {
	
	/**
	 * list of prescriptions prescribed 
	 */
	private final List<Prescription> prescriptionList;
	
	/**
	 * list of lab work performed
	 */
	private final List<LabWork> labWorkPerformed;
	
	/**
	 * medical instructions for treatment
	 */
	private String followUpInstructions;
	
	/**
	 * other additional medical instructions
	 */
	private String otherInstructions;
	
	/**
	 * Logger for all <code>PatientInstructions</code> instances.
	 */
	private static final Logger LOGGER =
		Logger.getLogger("edu.gatech.teama.doctorsoffice.server.ClientMessageHandler");

	static {
        FileHandler fh = null;
        try {
            fh = new FileHandler("application.log");
        } catch (SecurityException e) {
            LOGGER.log(Level.SEVERE,
            		"Security Exception creating the logger file handler");
            e.printStackTrace();
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "IO Exception creating the logger file handler");
            e.printStackTrace();
        }

        LOGGER.addHandler(fh);
        LOGGER.setLevel(Level.ALL);
    }
	
	/**
	 * Patient instructions resulting from an appointment, including follow-up 
	 * instructions and other instructions
	 * @param followUpInstructions
	 * @param otherInstructions
	 */
	public PatientInstructions(String followUpInstructions, String otherInstructions) { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods
		prescriptionList = new ArrayList<Prescription>();
		labWorkPerformed = new ArrayList<LabWork>();
		this.setFollowUpInstructions(followUpInstructions);
		this.setOtherInstructions(otherInstructions);
		LOGGER.info("New Patient Instructions: followUpInstructions= " + 
				followUpInstructions + " other instructions= " + otherInstructions + 
				" prescription list and lab work performed");
	}
	
	/**
	 * patient instructions constructor that sets both instructions to null
	 */
	public PatientInstructions() {
		this("", "");
	}
	
	/**
	 * Adds a prescription to the prescription list of a patient
	 * @param numberOfPills
	 * @param timesPerDay
	 * @param drugName
	 * @param otherInstructions 
	 */
	public void addPrescription(String drugName, int numberOfPills,
			int timesPerDay, String otherInstructions) {
		prescriptionList.add(new Prescription(drugName, numberOfPills, 
				timesPerDay, otherInstructions));
	}
	
	/**
	 * Adds a blood test to the lab work performed list
	 * @param results
	 */
	public void addBloodTest(String results) {
		labWorkPerformed.add(new BloodTest(results));
	}
	
	/**
	 * Adds a urine test to the lab work performed list
	 * @param results
	 */
	public void addUrineTest(String results) {
		labWorkPerformed.add(new UrineTest(results));
	}
	
	/**
	 * Adds an immunization to the lab work performed list
	 * @param immunizationName name of immunization
	 */
	public void addImmunization(String immunizationName) {
		labWorkPerformed.add(new Immunization(immunizationName));
	}

	/**
	 * Assigns follow-up instructions
	 * @param followUpInstructions
	 */
	public void setFollowUpInstructions(String followUpInstructions) {
		this.followUpInstructions = followUpInstructions;
	}

	/**
	 * Looks up follow up instructinos
	 * @return followUpInstructions
	 */
	public String getFollowUpInstructions() {
		return followUpInstructions;
	}

    /**
     * Assigns additional instructions
     * @param otherInstructions
     */
	public void setOtherInstructions(String otherInstructions) {
		this.otherInstructions = otherInstructions;
	}

   /**
    * Returns other additional instructions
    * @return otherInstructions
    */
	public String getOtherInstructions() {
		return otherInstructions;
	}

	/**
	 * Returns list of all prescriptions 
	 * @return prescriptionList
	 */
	public List<Prescription> getPrescriptionList() {
		return prescriptionList;
	}

	/**
	 * Returns list of lab work performed
	 * @return labWorkPerformed
	 */
	public List<LabWork> getLabWorkPerformed() {
		return labWorkPerformed;
	}
	
	public String toString() { // $codepro.audit.disable methodJavadoc
		String str = "";
		
		if (prescriptionList != null) {
			str += prescriptionList;
		}
		
		if (labWorkPerformed != null) {
			str += labWorkPerformed;
		}
		
		if (followUpInstructions != null) {
			str += followUpInstructions;
		}
		
		if (otherInstructions != null) {
			str += otherInstructions;
		}
		
		return str;
	}
}
